﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Twitter
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void registerBtn_Click(object sender, EventArgs e)
        {
            if (repeatPassWordBox.Text != passWordBox.Text)
            {
                ErrorPassWordLabel.Text = "Repeated password does not match!";
                return;
            }
            else
            {
                ErrorPassWordLabel.Text = "";

            }
            string user = userNameBox.Text;
            string password = passWordBox.Text;

            try
            {
                ChatDBAccess.Create.CreateUser(user, password, emailBox.Text);
            }
            catch (ArgumentException ar)
            {
                ErrorUserNameLabel.Text = "Username already used!";
                return;
            }
            ErrorUserNameLabel.Text = "";
            Page.Response.Redirect("~/Login.aspx");
        }
    }
}